package com.mk.admin.model;

import com.alibaba.fastjson2.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("返回结果")
public class ResultDto {
    @ApiModelProperty(value = "具体业务查询返回数据", notes = "分两种 \n" +
            "一种是直接业务数据对象\n" +
            "一种是分页对象")
    private Object result;
    @ApiModelProperty("响应数据条数")
    private Integer count;
    @ApiModelProperty(value = "状态码", notes = "T 代表请求成功\n" +
            "F代表请求失败")
    private String retCode;
    @ApiModelProperty(value = "错误编码", notes = "参看错误编码表")
    private String msgCode;
    @ApiModelProperty(value = "提示信息", notes = "提示信息（提示信息是 抱歉,服务器繁忙，请稍候再试!  时更新写入类接口需要再次确认是否成功）")
    private String msg;
    @ApiModelProperty(value = "响应时间", notes = "毫秒值，当前请求的服务器响应时间")
    private Long responseTime;
    @ApiModelProperty(value = "入参大小", notes = "入参占用内存容量  kb 为单位")
    private String inParamSize;

    public static ResultDto error(Object result) {
        return data(0, "error", "F", "T", result);
    }

    public static ResultDto data(String msg, Object result) {
        return data(0, msg, "T", "T", result);
    }

    public static ResultDto data(int count, Object result) {
        return data(count, "", "T", "T", result);
    }

    public static ResultDto data(String msg, String msgCode, Object result) {
        return data(0, msg, msgCode, "T", result);
    }

    public static ResultDto data(Object result) {
        return data(0, "", "T", "T", result);
    }

    public static ResultDto dataJson(int count, Object result) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", result);
        jsonObject.put("count", count);
        return data(0, "", "T", "T", jsonObject);
    }

    public static ResultDto dataJson(String result) {
        return data(0, "", "T", "T", JSONObject.parseObject(result));
    }

    public static ResultDto data(Integer count, String msg, String msgCode, String status, Object result) {
        return ResultDto.builder()
                .count(count)
                .msg(msg)
                .msgCode(msgCode)
                .retCode(status)
                .result(result)
                .build();
    }
}
